<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        main {
            margin: 100px auto;
            box-sizing: border-box;
            border: 1px solid transparent;
            text-align: center;
            margin-top: 30px;
            margin-bottom: 30px;
            height: 600px;
            width: 400px;
            background-color: rgb(197, 217, 255);
        }

        main h2 {
            margin-top: 30px;
            margin-bottom: 30px;
            font-size: 35px;
        }

        main .content {
            border-radius: 15px;
            box-sizing: border-box;
            border: 1px solid transparent;
            margin: 20px auto;
            background-color: aliceblue;
            width: 96%;
            height: 450px;
        }

        main .content h3 {
            font-size: 22px;
            margin: 30px auto;
        }

        main .content input {
            border: gainsboro solid 1px;
            border-radius: 10px;
            outline: none;
            margin: 15px auto;
            box-sizing: border-box;
            padding-left: 20px;
            width: 300px;
            height: 50px;
            margin-bottom: 20px;
        }

        main .content input:nth-child(5) {
            background-color: rgb(72, 133, 245);
            color: white;
            font-size: 20px;
        }
    </style>
</head>

<body>
    <main>
        <h2>阿里云盘</h2>
        <div class="content">
            <h3>注册新账号</h3>
            <input type="text" placeholder="请输入账号">
            <input type="password" placeholder="请输入密码">
            <input type="password" placeholder="确认密码">
            <input type="button" value="注册">
        </div>
    </main>
</body>

</html>
<script src="promise-ajax.js"></script>
<script>
    let inputss = document.querySelectorAll('input')
    inputss[3].onclick = function () {
        if (inputss[0].value && inputss[1].value) {
            if (/^\d{6}/.test(inputss[1].value)) {
                ajax('get', 'https://yantianfeng.com/api/register', {
                    username: inputss[0].value,
                    password: inputss[1].value,
                    password: inputss[2].value
                
                }).then((res)=>{
                    if (inputss[1].value == inputss[2].value) {
                        if (res.status == 200) {
                            alert(res.msg)
                        }else {
                            alert('注册失败,可能账号已注册')
                        }
                    }else {
                            alert('第一次和第二密码输入有误')
                        }
                })
            } else {
                alert('请输入正确的的账号或密码')
            }
        } else {
            alert('用户名或密码不能为空！')
        }
    }
</script>